<?php
namespace Home\Controller;
use Think\Controller;
class ComboController extends Controller {
    public function index(){
    	$this->display();
    }
    public function getComboList(){
    	$res = D('combo')->getComboList();
    	if(!$res){
    		return ajaxReturn(0,'获取失败');
    	}
    	return ajaxReturn(1,'获取成功',$res);
    }
    public function insert(){
    	$resResouse = D('resouse')->getResouseList();
    	$resCommand = D('command')->getCommandList();
    	$resCondition = D('condition')->getConditionList();
    	$this->assign('resouse',$resResouse);
    	$this->assign('command',$resCommand);
    	$this->assign('condition',$resCondition);
    	$this->display();
    }
    public function insertComboInfo(){
    	if(!isset($_POST['combo_name']) || !$_POST['combo_name']){
    		return ajaxReturn(0,'传参失败');
    	}
    	$res = D('combo')->insertComboInfo($_POST);
    	if(!$res){
    		return ajaxReturn(0,'添加失败');
    	}
    	return ajaxReturn(1,'添加成功');
    }
    public function revise(){
    	if(!isset($_GET['combo_id']) || !$_GET['combo_id']){
    		return ajaxReturn(0,'传参失败');
    	}
    	$res = D('combo')->getComboInfo($_GET);
    	if(!$res){
    		return ajaxReturn(0,'添加失败');
    	}
    	$resResouse = D('resouse')->getResouseList();
    	$resCommand = D('command')->getCommandList();
    	$resCondition = D('condition')->getConditionList();
    	$this->assign('resouse',$resResouse);
    	$this->assign('command',$resCommand);
    	$this->assign('condition',$resCondition);
    	$this->assign('combo',$res);
    	$this->display();
    }
    public function reviseComboInfo(){
    	if(!isset($_POST) || !$_POST){
    		return ajaxReturn(0,'传参失败');
    	}
    	$cond['resouse_id'] = $_POST['resouse_id'];
    	$res = D('combo')->reviseComboInfo($cond,$_POST);
    	if($res === false){
    		return ajaxReturn(0,'修改失败');
    	}
    	return ajaxReturn(1,'修改成功');
    }
    
    public function getConditionInfo(){
    	if(!isset($_POST) || !$_POST){
    		return ajaxReturn(0,'传参失败');
    	}
    	$res = D('condition')->getConditionInfo($_POST);
    	$data['condition'] = $res;
    	if($res['compare_id'] == 3 || $res['compare_id'] == 4){
    		$resNew = D('users')->getUserList();
    		$data['user'] = $resNew;
    	}
    	return ajaxReturn(1,'获取成功',$data);
    }
}